// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
var desktopCapturer = require('electron').desktopCapturer;

var socket = io.connect('ws://127.0.0.1:3000'); 
socket.emit("message", {"name" : 'electron', "msg" : "hello world" });


socket.on("message", function(obj) {
  console.log(obj);
});

  
desktopCapturer.getSources(  { types: ['window'], thumbnailSize: { width: 1200, height: 1200 } },
(error, sources) => {
  if (!error) {
      console.log(error)
    if (sources && sources.length > 0) {
      console.log(1)
      console.log(sources)
    }
  } 
}
)

      
setInterval(()=>{
   // socket.emit("message", {"name" : 'electron', "msg" : "hello world" });
      desktopCapturer.getSources(  { types: ['screen'], thumbnailSize: { width: 1200, height: 1200 } },
          (error, sources) => {
            if (!error) { 
              if (sources && sources.length > 0) { 
                console.log(sources)
              }
              sources.forEach(function (source) {
                if (source.name === 'npm' || source.name === 'Screen 1') {
                    socket.emit("message", {"name" : 'electron', "msg" :  source.thumbnail.toDataURL()  });
                     
                }
              })
            } 
          }
        )
  },1000)